package size;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Scanner;

public class ZTest {
    public static void main(String[] args) {

        int ysf; //运算符个数
        int num;  //题目个数
        
        int zhengque=0;  //正确数
        double zhengquelv;  //正确率

        String []Question;  //存放题目的数组

        Scanner scanner=new Scanner(System.in);
        System.out.print("题目个数： ");
        num=scanner.nextInt();

        Question=new String[num];//保存题目至特定数组

        System.out.print("每个题目的运算符个数： ");
        ysf=scanner.nextInt();

        Timushengcheng timushengcheng=new Timushengcheng(num,ysf);

        timushengcheng.QuestionNum();
        Question=timushengcheng.getArraylist();

        int start=0;

        while (start<num)
        {
            System.out.println("第"+(start+1)+"题： "+Question[start]+"\n"+"你的计算结果： ");
            String answer=scanner.next();

            Qzh trans=new Qzh(Question[start]);
            trans.qzh();

            String qzhed =trans.getLast();

            Jisuan  calcu=new Jisuan(qzhed);
            calcu.ToResult();
            String result=calcu.getResult();

            if (answer.equals(result)==true)
            {
                zhengque++;
                System.out.println("正确答案： "+result+" ,正确,继续作答");
                System.out.println();
            }

            else
            {
                System.out.println("正确答案： "+result+" ,错误,请继续作答");
                System.out.println();
            }

            start++;
        }

        System.out.println();

        zhengquelv=(double)zhengque/num;
        DecimalFormat fmt=new DecimalFormat("0.####");
        String accurancy2=fmt.format(zhengquelv);
        Double accurancy3=Double.valueOf(accurancy2);

        NumberFormat format = NumberFormat.getPercentInstance();

        System.out.println("共"+num+"道题目，答对"+zhengque+"道题目"+"\n正确率为: "+format.format(accurancy3));
        System.out.println();
        if (accurancy3<0.6)
        {
            System.out.println("不及格！");
        }
        else{
            if (accurancy3<0.9)
                System.out.println("良好！");
            else
                System.out.println("优秀");
        }
    }
}
